import electron from 'electron';

const { ipcMain } = electron;

const ipcCreators = {
  // 设置窗口大小
  setSize(win) {
    ipcMain.on('setSize', function (event, args) {
      win.setSize(args.width, args.height);
      // win.center()
    });
  },
  // 设置窗口xy坐标，大小
  setBounds(win) {
    ipcMain.on('setBounds', function (event, args) {
      win.setBounds({ ...args });
      win.center();
    });
  },
  //最小化窗口
  minimize(win) {
    ipcMain.on('minimize', function (event, args) {
      win.minimize();
    });
  },
  // 将窗口从最小化状态恢复到以前的状态
  restore(win) {
    ipcMain.on('restore', function (event, args) {
      win.restore();
    });
  },
  quit(win, app) {
    ipcMain.on('quit', function (event, args) {
      app.quit();
    });
  },
};
export { ipcCreators };

export default function ipcMainInit(win, app) {
  Object.keys(ipcCreators).forEach((key) => {
    ipcCreators[key](win, app);
  });
}
